//=============================================================================
// pgPlayer
//=============================================================================
class pgPlayer extends KFHumanPawn;

var transient float NextVolumePainTime;
var transient pgFlyAmbSound FlySound[2];

simulated function PostBeginPlay()
{
	Super(UnrealPawn).PostBeginPlay();

	AssignInitialPose();
	if( bActorShadows && bPlayerShadows && (Level.NetMode!=NM_DedicatedServer) )
	{
		if( bDetailedShadows )
			PlayerShadow = Spawn(class'KFShadowProject',Self,'',Location);
		else PlayerShadow = Spawn(class'ShadowProjector',Self,'',Location);
		PlayerShadow.ShadowActor = self;
		PlayerShadow.bBlobShadow = bBlobShadow;
		PlayerShadow.LightDirection = Normal(vect(1,1,3));
		PlayerShadow.InitShadow();
	}
}
simulated function Destroyed()
{
	if( FlySound[0]!=None )
		FlySound[0].Destroy();
	if( FlySound[1]!=None )
		FlySound[1].Destroy();
	Super.Destroyed();
}
simulated final function UpdateFallSound()
{
	local float Speed;

	Speed = VSizeSquared(Velocity);
	if( Speed>810000 ) // 900^2
	{
		if( FlySound[0]==None )
			FlySound[0] = Spawn(Class'pgFlyAmbSound',Self);
		if( PhysicsVolume!=None && PhysicsVolume.AmbientSound!=None )
		{
			if( FlySound[1]==None )
				FlySound[1] = Spawn(Class'pgFlyAmbSound',Self);
			FlySound[1].AmbientSound = PhysicsVolume.AmbientSound;
		}
		else if( FlySound[1]!=None )
			FlySound[1].AmbientSound = None;
		FlySound[0].SoundVolume = Min(255,(Speed-810000.f)/6627.f); // 1300^2/255
	}
	else FlySound[0].SoundVolume = 0;
	if( FlySound[1]!=None )
		FlySound[1].SoundVolume = FlySound[0].SoundVolume;
}
simulated event ModifyVelocity(float DeltaTime, vector OldVelocity)
{
	if( Level.NetMode!=NM_DedicatedServer && PlayerController(Controller)!=None && Viewport(PlayerController(Controller).Player)!=None && Health>0 )
		UpdateFallSound();
	else
	{
		if( FlySound[0]!=None )
			FlySound[0].Destroy();
		if( FlySound[1]!=None )
			FlySound[1].Destroy();
	}
}

function TakeFallingDamage();

simulated function PlayDirectionalDeath(Vector HitLoc)
{
	LifeSpan = 1.f;
}

function PlayMoverHitSound();

// Smooth pitch limitation.
simulated function int LimitPitch(int pitch, optional float DeltaTime)
{
	pitch = pitch & 65535;
	if( pitch<32768 )
	{
		if( pitch>PitchUpLimit )
			pitch = Class'pgPlayerController'.Static.FixedTurn(pitch,PitchUpLimit,Max(65535*DeltaTime,1000));
	}
	else if( pitch<PitchDownLimit )
		pitch = Class'pgPlayerController'.Static.FixedTurn(pitch,PitchDownLimit,Max(65535*DeltaTime,1000));
	return pitch;
}

defaultproperties
{
	MaxCarryWeight=60
	PitchUpLimit=16380
	PitchDownLimit=49142
	bNoTeamBeacon=true
}